//
//  MeTableHeaderView.swift
//  MyWeiBlog
//
//  Created by laichunhui on 15/10/19.
//  Copyright © 2015年 lch. All rights reserved.
//

import UIKit

class MeTableHeaderView: UIView {
    
    lazy var user = UserAccountViewModel.shareUserAccountViewModel.userAccount?.user
    
    @IBOutlet weak var iconView: UIImageView!
    
    @IBOutlet weak var nameLabel: LTMorphingLabel!
    
    @IBOutlet weak var followsLabel: UILabel!
    
    @IBOutlet weak var friendsLabel: UILabel!
    
    class func meTableHeaderViewFromNib(frame: CGRect) -> MeTableHeaderView {
        
        let nibView = NSBundle.mainBundle().loadNibNamed("MeTableHeaderView", owner: nil, options: nil).last as! MeTableHeaderView
        nibView.frame = frame
        
        return nibView 
    }
    
    override func awakeFromNib() {
        
        
        UMSocialDataService.defaultDataService().requestSnsInformation(UMShareToSina) { (response) -> Void in
            
            self.iconView.xs_setCircleIconViewWithURL(NSURL(string: (response.data["profile_image_url"] as? String)!)!)
            // iconView.image =  UIImage(named: "avatar_default_big") 在此处无法修改iconView的Image属性，因为sd图片加载是一个异步请求，也就是此时设置的属性会被之后加载的覆盖，必须在请求的回调中才能修改
            self.nameLabel.morphingEffect = .Burn
            self.nameLabel.text = response.data["screen_name"] as? String
            self.friendsLabel.text = "关注 \(response.data["friends_count"] as! Int)"
            self.followsLabel.text = "粉丝 \(response.data["followers_count"] as! Int)"
        }
      
    }
    
}

